package controll;

import com.sun.org.apache.regexp.internal.RE;
import dao.CountryDao;
import entity.Countries;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/login.do")//Servlet获取用户提交的请求 映射路径
public class Login extends HttpServlet {
    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws
        ServletException, IOException {
        doGet(request,response);

    }

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws
            ServletException, IOException {

//        ServletContext sc=request.getServletContext();
//        InputStream in=sc.getResourceAsStream("/WEB-INF/db.properties");
//        Properties pro=new Properties();
//        pro.load(in);
//        String url=pro.getProperty("user");
       // System.out.println("user==>"+url);
        String s=request.getRequestURI();
        String s2=request.getRequestURL().toString();
        String s3= request.getContextPath();
        String s4=request.getServletPath();
        System.out.println(" =>"+s+" =>"+s2+"   =>"+s3+"   =>"+s4);
        request.setCharacterEncoding("utf-8");
        String user=request.getParameter("user");
        String password=request.getParameter("pwd");
       response.setContentType("text/html;charset=utf-8");
        CountryDao cd=new CountryDao();
        List<Countries> cts=cd.findAll();
        PrintWriter out=response.getWriter();
        out.write("<html><head><title>登录成功</title></head>");
        out.write("<body>");
        out.write("<h1>"+user);
        out.write("<table border='1' cellpadding=\"5\">");
        for (Countries c:cts){
            out.write("<tr>");
            out.write("<td>"+c.getCountryId()+"</td>");
            out.write("<td>"+c.getCountryName()+"</td>");
            out.write("<td>"+c.getRegion_id()+"</td>");
            out.write("</tr>");
        }
        out.write("</table>");
        out.write("</body></html>");
        out.close();



    }
//    @Override
//    public void init(ServletConfig config) throws ServletException{
//        super.init(config);
//    }

}
